package model

import (
	"database/sql/driver"
	"encoding/json"
	"sensi/common/sys/database"
)

type WeatherDaily struct {
	City     string           `json:"city"`
	InDay    string           `json:"in_day"`
	Location string           `json:"location"`
	Weather  WeatherForecasts `json:"weather_forecast"`
	database.Model
}

func (WeatherDaily) TableName() string {
	return "weather_daily"
}

type WeatherForecast struct {
	FxDate    string `json:"fx_date"`
	TempMax   string `json:"temp_max"`
	TempMin   string `json:"temp_min"`
	IconDay   string `json:"icon_day"`
	IconNight string `json:"icon_night"`
	Humidity  string `json:"humidity"`
}

type WeatherForecasts []*WeatherForecast

// Value ...
func (w WeatherForecasts) Value() (driver.Value, error) {
	b, err := json.Marshal(w)
	return string(b), err
}

// Scan ...
func (w *WeatherForecasts) Scan(input interface{}) error {
	return json.Unmarshal(input.([]byte), w)
}
